//
//  ShopListTableViewCell.m
//  BaseFrame
//
//  Created by 孟学浩 on 2017/4/5.
//  Copyright © 2017年 com.mxh. All rights reserved.
//

#import "ShopListTableViewCell.h"

@interface ShopListTableViewCell()

@property (nonatomic,strong) UIImageView *imgView;
@property (nonatomic,strong) UILabel *infoLabel;
@property (nonatomic,strong) UILabel *buyLabel;

@end

@implementation ShopListTableViewCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier{
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        self.selectionStyle = 0;
        _imgView = [UIImageView new];
        _imgView.contentMode = UIViewContentModeScaleAspectFit;
        
        _infoLabel = [UILabel new];
        _infoLabel.numberOfLines = 0;
        _infoLabel.font = DEF_FontSize_13;
        
        _buyLabel = [UILabel new];
        _buyLabel.numberOfLines = 2;
        _buyLabel.text = @"查看\n详情";
        _buyLabel.textColor = [UIColor whiteColor];
        _buyLabel.backgroundColor = getColor(redColor);
        _buyLabel.layer.masksToBounds = YES;
        _buyLabel.layer.cornerRadius = 8;
        _buyLabel.font = [UIFont systemFontOfSize:12 weight:1];
        _buyLabel.textAlignment = NSTextAlignmentCenter;
        
        [self.contentView addSubview:_imgView];
        [self.contentView addSubview:_infoLabel];
        [self.contentView addSubview:self.buyLabel];
    }
    
    return self;
}

- (void)layoutSubviews{
    [super layoutSubviews];
    _imgView.frame = CGRectMake(12, 0, self.frame.size.height-15, self.frame.size.height-15);
    _imgView.center = CGPointMake(_imgView.center.x, self.frame.size.height/2.);
    
    _infoLabel.frame = CGRectMake(CGRectGetMaxX(_imgView.frame)+5, 0, SCREEN_WIDTH - CGRectGetMaxX(_imgView.frame) - 60, self.frame.size.height);
    _buyLabel.frame = CGRectMake(SCREEN_WIDTH-50, 0, 40, 40);
    _buyLabel.center = CGPointMake(_buyLabel.center.x, self.frame.size.height/2.);
}

- (void)setModel:(ShopModel *)model{
    _model = model;
    [_imgView sd_setImageWithURL:[NSURL URLOffsetIPWithString:_model.cPictures] placeholderImage:[UIImage imageNamed:@"image"]];
    
    NSString *title = _model.sName;
    NSString *info = _model.qualified;
    NSString *address = _model.address;
    NSString *temp = [NSString stringWithFormat:@"%@\n%@\n%@",title,info,address];
    
    NSMutableAttributedString *attStr = [[NSMutableAttributedString alloc] initWithString:temp];
    [attStr addAttribute:NSForegroundColorAttributeName value:getColor(@"545454") range:[temp rangeOfString:info]];
    
    NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc] init];
    [paragraphStyle setLineSpacing:4];//调整行间距
    [attStr addAttribute:NSParagraphStyleAttributeName value:paragraphStyle range:NSMakeRange(0, [temp length])];
    
    _infoLabel.attributedText = attStr;
}

- (void)setDataDictionary:(NSDictionary *)dataDictionary{
    _dataDictionary = dataDictionary;
    _imgView.image = [UIImage imageNamed:@"img"];
    
    NSString *title = @"品牌名称";
    NSString *info = @"用户好评率90%%";
    NSString *temp = [NSString stringWithFormat:@"%@\n%@\n",title,info];
    
    NSMutableAttributedString *attStr = [[NSMutableAttributedString alloc] initWithString:temp];
    [attStr addAttribute:NSForegroundColorAttributeName value:getColor(@"545454") range:[temp rangeOfString:info]];
    for (int i = 0; i<5; i++) {
        NSTextAttachment *attText = [NSTextAttachment new];
        attText.image = [UIImage imageNamed:@"xin"];
        attText.bounds = CGRectMake(0, 0, 12, 10);
        [attStr appendAttributedString:[NSAttributedString attributedStringWithAttachment:attText]];
    }
    
    
    NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc] init];
    [paragraphStyle setLineSpacing:4];//调整行间距
    [attStr addAttribute:NSParagraphStyleAttributeName value:paragraphStyle range:NSMakeRange(0, [temp length])];
    
    _infoLabel.attributedText = attStr;
    
}

@end
